<template>
    <view class="pub_page pub_mine_tuanz pub_header_padding">
        <pub-head headerName="mine_info" :headerConfig="headerConfig"></pub-head>
        <div class="pub_page_scroll page_box" v-if="teamType != -1">
            <br>
            <div class="info_div">
                <div class="pub_inputs">
                    <div class="abox">
                        <div class="ali ali_align_right">
                            <div class="atitle">姓名</div>
                            <input class="ainput" type="text" :value="userInfo.cardName" disabled>
                        </div>
                        <div class="ali ali_align_right">
                            <div class="atitle">年龄</div>
                            <input class="ainput" type="text" :value="userInfo.age" disabled>
                        </div>
                        <div class="ali ali_align_right">
                            <div class="atitle">联系电话</div>
                            <input class="ainput" type="text" :value="userInfo.mobile" disabled>
                        </div>
                        <chooseAddressComponents ref="chooseAddressComponents" :isEdit="isEdit"
                            :baseAddress="baseAddress" />
                    </div>
                </div>
            </div>
            <br>
            <div class="document" v-if="documentInfo != ''">
                <div class="title">申请团长要求</div>
                <div class="content" v-html="documentInfo.noticeContent"></div>
            </div>
            <br>
            <div v-if="teamType===0" class="pub_btn" @click="toSubmit">确定保存</div>
            <div v-if="teamType===1" class="pub_btn">审核中</div>
            <div v-if="teamType===3" class="pub_btn">您的申请未通过</div>
        </div>
    </view>
</template>

<script>
import chooseAddressComponents from '../../components/chooseAddress/index.vue';
export default {
    components: {
        chooseAddressComponents
    },
    data() {
        return {
            pagescrollTop: 0,
            headerConfig: {
                title: '利商团长',//标题栏内容
                left_type: 3,
                header_color: '#fff',
                title_color: '#000',
                left_content: 'dark',
            },

            documentInfo: '',

            userInfo: '',

            teamType: -1,//0：不是团长 1：申请中 2：团长 3：已驳回

            baseAddress: {}
        };
    },
    computed: {
        isEdit() {
            return this.teamType === 0
        }
    },
    onLoad() {
        this.getDocumentInfo();
        this.getUserInfo({ needReloadUserInfo: false });
        this.getTeamLeaderInfo()
    },
    methods: {
        async getDocumentInfo() {
            this.$comFun.openLoading();
            const res = await this.$request.get('public/getArchivesInfo', {
                id: '1925209870251274242'
            });
            // console.log(res);
            this.$comFun.closeLoading();
            if (res.code == 200 && res.result) {
                this.documentInfo = res.result;
            }
        },
        async getTeamLeaderInfo() {
            const res = await this.$request.get('user/getTeamLeaderInfo');
            if (res.code == 200) {
                this.teamType = res.result?.status || 0;
                this.baseAddress = res.result
            }
        },
        toSubmit() {
            const addressInfo = this.$refs.chooseAddressComponents?.getAddressInfo()
            if (!addressInfo?.provinceId) {
                this.$comFun.toast('请选择所在地区');
                return;
            }
            if (!addressInfo?.address) {
                this.$comFun.toast('请输入详细地址');
                return;
            }
            this.sureSubmit(addressInfo);
        },
        async sureSubmit(addressInfo) {
            this.$comFun.openLoading();
            const res = await this.$request.post('user/applyTeamLeader', {
                address: addressInfo.address,
                cityId: addressInfo.cityId,
                provinceId: addressInfo.provinceId,
                regionId: addressInfo.regionId,
            });
            this.$comFun.closeLoading();
            this.$comFun.toast(res.message);
            if (res.code == 200) {
                this.getTeamLeaderInfo()
            }
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/mine.scss";
</style>
